package com.sky.demo.activities;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.sky.demo.R;
import com.sky.demo.bitmap.ImageUtils;
import com.sky.demo.global.BaseActivity;
import com.sky.demo.views.ZoomImageView;

/**
 * @author 彬 QQ 1136096189
 * @Description: 图片的缩放
 * @date 2015/7/17 15:08
 */
public class ZoomImageActivity extends BaseActivity {
    private ViewPager viewPager;
    private int[] images = new int[]{R.mipmap.couponhome_icon, R.mipmap.background, R.mipmap.main_menu};
    private Bitmap[] bitmap = new Bitmap[3];
    private ImageView[] imageViews = new ImageView[images.length];

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zoom);
        viewPager = (ViewPager) findViewById(R.id.viewPager);
        bitmap[0]= ImageUtils.handlerImageNegative(BitmapFactory.decodeResource(getResources(), images[0]));
        bitmap[1]= ImageUtils.handlerImageOldPhoto(BitmapFactory.decodeResource(getResources(), images[1]));
        bitmap[2]= ImageUtils.handlerImagePixelsrelier(BitmapFactory.decodeResource(getResources(), images[2]));
        viewPager.setAdapter(new PagerAdapter() {
            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                ZoomImageView imageView = new ZoomImageView(getApplicationContext());
//                Bitmap bitmap=BitmapFactory.decodeResource(getResources(), images[position]);

//                imageView.setImageResource(images[position]);
                imageView.setImageBitmap(bitmap[position]);
                container.addView(imageView);
                imageViews[position] = imageView;
                return imageView;
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView(imageViews[position]);
            }

            @Override
            public int getCount() {
                return images.length;
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }
        });
    }
}
